/**
 * 验证姓名不为空
 */
function checkNickName(){
	var nickName = $.trim($("#nickname").val());
	var falg = true;
	if(nickName == null ||nickName == "" || nickName == "姓名"){
		layer.tips("请输入姓名", "#nickname", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 验证用户名不为空
 */
function checkUserName(){
	var userName = $.trim($("#username").val());
	var falg = true;
	if(userName == null || userName == "" || userName == "用户名"){
		layer.tips("请输入用户名", "#username", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 验证电话不为空和格式不对
 */
function checkTelPhone(){
	var phoneNum = $.trim($("#telphone").val());
	var falg = true;
	if(phoneNum == null || phoneNum == ""||!(/^1[3456789]\d{9}$/.test(phoneNum)) ){
		layer.tips("请重新输入手机号", "#telphone", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}


/**
 * 验证密码不为空
 */
function checkPassWord(){
	var password = $.trim($("#password").val());
	var newpassword = $.trim($("#new_password").val());
	var falg = true;
	if(password == null || password == "" || password == "密码"){
		layer.tips("请输入密码", "#password", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	if(password!=newpassword){
		layer.tips("两次密码不一致", "#new_password", {tips: [2, "#E34127"],time: 500});
		falg= false;
	}
	return falg;
}





/**
 * 用户登录
 */
function updateUserInfo(){
	if(checkNickName()&&checkTelPhone()&&checkUserName()&&checkPassWord()){
		var userName = $.trim($("#username").val());
		var passWord = $.trim($("#new_password").val());
		var telphone=$.trim($("#telphone").val());
		var nickname=$.trim($("#nickname").val());
		$.ajax({
			type : "post",
			url : "/member/update/userinfo",
			async : false,
			data : {
				userName : userName,
				passWord : passWord,
				telphone :telphone,
				nickname:nickname
			},
			dataType:"json",
			success : function(data){
				if(data.status== 1){
					layer.msg(data.msg, {icon: 6});
				}else if(data.status==0){
					layer.msg(data.msg, {icon: 5});
				}
				
			}
		});
	}
}
//回车触发登录
function updateUser(e){
	  var theEvent = window.event || e;
	      var code = theEvent.keyCode || theEvent.which;
	   if (code==13) {  //回车键的键值为13
		   updateUserInfo();  //调用提交登录
	   }
	  }